/**
 * Copyright 2012 Fonfon.Fenceer
 * All rights reserved.
 * 
 * @project 
 * @author Fonfon.Fenceer
 * @version 1.0
 * @data 2012-3-29
 */
package com.guidecaptain.java.action;

import net.sf.json.JSONObject;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.guidecaptain.core.base.action.BaseAction;
import com.guidecaptain.java.model.pojo.Uploadify;
import com.guidecaptain.java.model.vo.ScanpicVO;
import com.guidecaptain.java.model.vo.UploadifyVO;
import com.guidecaptain.java.service.ScanpicService;
import com.guidecaptain.java.service.UploadService;

/**
 * 
 * @author fenceer
 */
@Controller
@Scope("prototype")
public class ScanpicAction extends BaseAction{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	@Autowired
	private ScanpicService scanpicService;
	@Autowired
	private UploadService uploadService;
	
	private ScanpicVO scanpicVO=new ScanpicVO();
	
	public String uploadScanpic(){
		UploadifyVO uploadifyVO=new UploadifyVO();
		uploadifyVO.setUserId(scanpicVO.getUserId());
		uploadifyVO.setUploadify(scanpicVO.getUploadify());
		uploadifyVO.setUploadifyFileName(scanpicVO.getUploadifyFileName());
		Uploadify uploadify  =uploadService.insertUploadify(uploadifyVO);
		
		JSONObject jsonObject = new JSONObject();
		if (uploadify != null) {
			scanpicVO.setPicName(uploadify.getFileName());
			scanpicVO.setScanpicAddr(uploadify.getFilePath());
			if (scanpicService.insertScanpic(scanpicVO) > 0) {
				jsonObject.put("filePath", uploadify.getFilePath());
				jsonObject.put("fileName", uploadify.getFileName());
				
			} else {

				jsonObject.put("state", "insertfail");
			}

		} else {
			
			jsonObject.put("state", "uploadfail");
		}

		setJsonObject(jsonObject);
		return JSON;
	}

	/** 
	 * @param 
	 * @return 
	 */
	@Override
	public Object getModel() {
		
		return scanpicVO;
	}

}
